home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Storage / TransDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  24.1 KB  |  842 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TransDlg.cpp
  3.  
  4.     Contains:    C++ Implementation for Translation Dialog class.
  5.  
  6.     Owned by:    Craig Carper
  7.  
  8.     Copyright:    © 1993-95 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <30>    10/16/95    CC        GM 1291441: InitialEditorSetup: Translation
  13.                                     disabled if only one translate-kind
  14.                                     possible.
  15.                                     GM 1292157: Removed static function
  16.                                     GetEditorFromList; call
  17.                                     GetThisEditorFromList instead.
  18.         <29>     10/3/95    eeh        1284995: new default param to
  19.                                     SetDialogTextStyle
  20.         <28>     9/12/95    DM        1280020 FB1 part trans dlg mem leaks
  21.         <27>      9/7/95    CG        #1229981 FB2:No Trans dlg when no
  22.                                     translators are installed.
  23.         <26>     8/30/95    EL        1279451: Translation dialog problem if
  24.                                     exception thrown.
  25.         <25>     8/25/95    eeh        1230007: new param to DrawITextInDlogBox
  26.         <24>     8/24/95    CC        1242669,1279966,1279963: Fixes to
  27.                                     ShowTranslationDialog.
  28.         <23>     8/23/95    CC        1242581: ShowTranslateDialog: Copy selected
  29.                                     editor on return if OK button pressed.
  30.         <22>     7/28/95    CC        1258538: Remove declaration of
  31.                                     GetFromAndToKinds.
  32.         <21>     7/26/95    DM        #1270320: Memory leak fixes.
  33.         <20>     6/21/95    CC        1260937: BB: ODTypeListIterator must return
  34.                                     copies of ODType values.
  35.         <19>     6/16/95    CC        1258538: ShowTranslateDialog: Release kind
  36.                                     and editor menu resources; also check
  37.                                     GetMenu result; Added TRY block.
  38.                                     Added GetOrderedCollectionElement.
  39.                                     Removed GetFromAndToKinds.
  40.                                     1259356: ShowPartTranslateDialog:
  41.                                     ChangeKind or externalize before attempting
  42.                                     translation.
  43.                                     1259719: ShowPartTranslateDialog: Use
  44.                                     ChangeKindAndEditor.
  45.                                     Added #includes of OrdColl.h and
  46.                                     StdTypIO.h.
  47.         <18>      6/7/95    jpa        Fixed EndUsingLibRsrcs calls. [1255369]
  48.         <17>      6/7/95    CC        1236299: Moved CUsingLibraryResources call
  49.                                     from ShowPartTranslateDialog to
  50.                                     ShowTranslateDialog.  Wrapped other uses of
  51.                                     resource manager with
  52.                                     BeginUsingLibraryResources and
  53.                                     EndUsingLibraryResources.
  54.         <16>      6/2/95    CC        1236617: Use CreateTypeList factory method.
  55.         <15>     5/26/95    VL        1251403: Multithreading naming support.
  56.         <14>     5/18/95    CG        #1249263 BB: BndNSUtl.cpp does not compile
  57.                                     standalone.
  58.         <13>      5/1/95    CG        #1240845    BB: Kinds popups need to include
  59.                                     all kinds that an editor can edit.
  60.         <12>     4/25/95    CC        1242555: $5 entered as bug 1242666.
  61.                                     1242555: ShowTranslateDialog: $5 entered as
  62.                                     bug 1242669.
  63.         <11>     4/14/95    TÇ        #1235279 BB: InfoUtil & StdTypIO functions
  64.                                     should take Environment* and SU* when
  65.                                     possible
  66.         <10>     3/28/95    CC        1229640: Added forPaste parameter to
  67.                                     ShowTranslateDialog.
  68.                                     DrawEditorName calls DrawITextInDlogBox
  69.                                     utility.
  70.          <9>     3/28/95    CC        1233117: Removed unused ODStorageUnit
  71.                                     parameter from  ShowPartTranslateDialog.
  72.                                     1232850: Fixed bug causing crash.
  73.          <8>     3/27/95    CC        1229640: Split ShowTranslateDialog() into
  74.                                     two methods: ShowPartTranslateDialog() and
  75.                                     ShowPartTranslateDialog().  Many changes to
  76.                                     support display from Paste As dialog.
  77.          <7>      3/6/95    jpa        Use dialog utilities (ODGetNewDialog,
  78.                                     ODDialogFilterProc) to make dlogs movable.
  79.                                     [1218957]
  80.          <6>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  81.          <5>     1/10/95    CG        1197870: If no Part is root and TransDlg is
  82.                                     dismissed, close document.
  83.          <4>    12/23/94    JBS        1186869: hide ODPartWrapper from public
  84.                                     API; 1192557: ODPartWrapper realPart access
  85.          <3>    12/20/94    CG        #1207346: Switching editors was crashing.
  86.          <2>    12/13/94    CG        #1187128: Added StorageUnit and PartWrapper
  87.                                     parameters to ShowTranslateDialog().
  88.          <1>    11/17/94    CG        first checked in
  89.     To Do:
  90.     In Progress:
  91.         
  92. */
  93.  
  94. #ifndef _TRANSDLG_
  95. #include "TransDlg.h"
  96. #endif
  97.  
  98. #ifndef _TRNDLGDF_
  99. #include <TrnDlgDf.h>
  100. #endif
  101.  
  102. #ifndef _USERSRCM_
  103. #include <UseRsrcM.h>
  104. #endif
  105.  
  106. #ifndef __DIALOGS__
  107. #include <Dialogs.h>
  108. #endif
  109.  
  110. #ifndef SOM_ODSession_xh
  111. #include <ODSessn.xh>
  112. #endif
  113.  
  114. #ifndef SOM_ODPart_xh
  115. #include <Part.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODStorageSystem_xh
  119. #include <ODStor.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODStorageUnit_xh
  123. #include <StorageU.xh>
  124. #endif
  125.  
  126. #ifndef SOM_ODTypeList_xh
  127. #include <TypeList.xh>
  128. #endif
  129.  
  130. #ifndef SOM_ODTypeListIterator_xh
  131. #include <TypLsItr.xh>
  132. #endif
  133.  
  134. #ifndef _BINDNGH_
  135. #include <BindngH.h>
  136. #endif
  137.  
  138. #ifndef _BNDNSUTL_
  139. #include <BndNSUtl.h>
  140. #endif
  141.  
  142. #ifndef _ODUTILS_
  143. #include <ODUtils.h>
  144. #endif
  145.  
  146. #ifndef _PASCLSTR_
  147. #include <PasclStr.h>
  148. #endif
  149.  
  150. #ifndef _DLOGUTIL_
  151. #include <DlogUtil.h>
  152. #endif
  153.  
  154. #ifndef SOM_ODFrame_xh
  155. #include <Frame.xh>
  156. #endif
  157.  
  158. #ifndef SOM_ODWindowState_xh
  159. #include <WinStat.xh>
  160. #endif
  161.  
  162. #ifndef SOM_Module_OpenDoc_StdProps_defined
  163. #include <StdProps.xh>
  164. #endif
  165.  
  166. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  167. #include <StdTypes.xh>
  168. #endif
  169.  
  170. #ifndef SOM_ODTranslation_xh
  171. #include <Translt.xh>
  172. #endif
  173.  
  174. #ifndef _EDITRSET_
  175. #include <EditrSet.h>
  176. #endif
  177.  
  178. #ifndef SOM_ODPartWrapper_xh
  179. #include <PartWrap.xh>
  180. #endif
  181.  
  182. #include <somcls.xh>
  183. #include <somcm.xh>
  184.  
  185. #ifndef _ODMEMORY_
  186. #include <ODMemory.h>
  187. #endif
  188.  
  189. #ifndef __TEXTUTILS__
  190. #include <TextUtils.h>
  191. #endif
  192.  
  193. #ifndef _INFOUTIL_
  194. #include <InfoUtil.h>
  195. #endif
  196.  
  197. #ifndef _TRANSUTL_
  198. #include <TransUtl.h>
  199. #endif
  200.  
  201. #ifndef _ORDCOLL_
  202. #include "OrdColl.h"
  203. #endif
  204.  
  205. #ifndef _STDTYPIO_
  206. #include "StdTypIO.h"
  207. #endif
  208.  
  209. #ifndef _TEMPOBJ_
  210. #include <TempObj.h>
  211. #endif
  212.  
  213. #ifndef _ISOSTR_
  214. #include <ISOStr.h>
  215. #endif
  216.  
  217. #pragma segment TransDlg
  218.  
  219. //==============================================================================
  220. // Constants
  221. //==============================================================================
  222.  
  223. const Boolean kNoDefaultButton = kODFalse;
  224.  
  225. const short kControlInactive = 255;
  226. const short kControlActive = 0;
  227.  
  228. //==============================================================================
  229. // Scalar Types
  230. //==============================================================================
  231.  
  232. //==============================================================================
  233. // Local Classes
  234. //==============================================================================
  235.  
  236. //==============================================================================
  237. // Global Variables
  238. //==============================================================================
  239.  
  240. // Use a global to pass the editor name to DrawEditorName
  241. ODStatic ODName* gEditorName = kODNULL;
  242.  
  243. //==============================================================================
  244. // Function Prototype
  245. //==============================================================================
  246. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name);
  247.  
  248. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item);
  249.  
  250. ODStatic ODType GetTypeListItem(ODTypeList* typeList, ODUShort index);
  251.  
  252. ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index);
  253.  
  254. //==============================================================================
  255. // Local Functions
  256. //==============================================================================
  257.  
  258. //------------------------------------------------------------------------------
  259. // DisposeGlobalODNameAndZeroPtr
  260. //------------------------------------------------------------------------------
  261. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name)
  262. {
  263.     if (*name)
  264.     {
  265.         // simple way to force deletion of old name value without knowing
  266.         // that DisposeIText is the right way to destroy an ODName:
  267.         TempODName tempName = *name;
  268.         *name = kODNULL;
  269.     }
  270. }
  271.  
  272. //------------------------------------------------------------------------------
  273. // DrawEditorName
  274. //------------------------------------------------------------------------------
  275.  
  276. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item)
  277. {
  278.     short            itemType;
  279.     Handle            itemHandle;
  280.     Rect            itemRect;
  281.  
  282.     GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  283.  
  284.     if ( gEditorName )
  285.         DrawITextInDlogBox(gEditorName, &itemRect, dialog, kODTrue);
  286. }
  287.  
  288. //------------------------------------------------------------------------------
  289. // GetTypeListItem 
  290. //------------------------------------------------------------------------------
  291.  
  292. ODStatic ODType GetTypeListItem(ODTypeList* typeList, ODUShort index)
  293. {
  294.     Environment* ev = somGetGlobalEnvironment();
  295.     ODType theType = kODNULL;
  296.  
  297.     if ( index > 0 )
  298.     {
  299.         ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
  300.     
  301.         for (theType = typeIter->First(ev);
  302.              (typeIter->IsNotComplete(ev)) && (index > 1);
  303.              theType = typeIter->Next(ev), --index)
  304.         {
  305.             ODDisposePtr(theType);
  306.         }
  307.     
  308.         delete typeIter;
  309.     }
  310.     
  311.     return theType;
  312. }
  313.  
  314. //------------------------------------------------------------------------------
  315. // GetOrderedCollectionElement
  316. //------------------------------------------------------------------------------
  317.  
  318. ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index)
  319. {
  320.     OrderedCollectionIterator* oci = collection->CreateIterator();
  321.  
  322.     ODUShort elem = 0;
  323.  
  324.     for (    elem = (ODUShort) oci->First();
  325.             oci->IsNotComplete(); 
  326.             elem = (ODUShort) oci->Next() )
  327.     {
  328.         if ( --index == 0 )
  329.             break;
  330.     }
  331.  
  332.     ODDeleteObject(oci);
  333.  
  334.     return elem;
  335. }
  336.  
  337. //------------------------------------------------------------------------------
  338. // InitialEditorSetup
  339. //------------------------------------------------------------------------------
  340. // On entry, kindIndex identifies the preferred kind in kindList.
  341. // Returns in kindIndex the index into kindList of a type for which editors are
  342. // available.  If none are available, kindIndex is unchanged, and the returned
  343. // editor set is empty.
  344. ODStatic EditorSet* InitialEditorSetup(
  345.                         ODTypeList*        kindList,
  346.                         ODUShort*        kindIndex,
  347.                         MenuHandle        editorMenu, 
  348.                         ControlHandle    popupCtlHndl, 
  349.                         ODSession*        session)
  350. {
  351.     // Create an empty editor list
  352.     EditorSet* editorList = new EditorSet;
  353.     editorList->InitEditorSet();
  354.  
  355.     Environment* ev = somGetGlobalEnvironment();
  356.  
  357.     ODUShort kindItems = kindList->Count(ev);
  358.  
  359.     if ( (*kindIndex > 0) && (*kindIndex <= kindItems) )
  360.     {
  361.          TempODType initialKind = GetTypeListItem(kindList, *kindIndex);
  362.          if ( initialKind )
  363.             SetupEditorMenu(initialKind, editorList, editorMenu, popupCtlHndl, session);
  364.      }
  365.  
  366.     // If the initial kind is supported by at least one editor, 
  367.     // or there is no other kind, return
  368.     if ( (editorList->GetEditorCount() > 0) || (kindItems < 2) )
  369.         return editorList;
  370.  
  371.     ODUShort index = 1;
  372.     ODTypeListIterator* iter = kindList->CreateTypeListIterator(ev);
  373.  
  374.     TempODType kind = kODNULL;
  375.     for (kind = iter->First(ev);
  376.          iter->IsNotComplete(ev);
  377.          kind = iter->Next(ev))
  378.     {
  379.         if ( SetupEditorMenu(kind, editorList, editorMenu, popupCtlHndl, session) )
  380.         {
  381.             *kindIndex = index;
  382.             break;
  383.         }
  384.         ODDisposePtr(kind);
  385.         kind = kODNULL;
  386.         ++index;
  387.     }
  388.     delete iter;
  389.  
  390.     return editorList;
  391. }    
  392.  
  393. //------------------------------------------------------------------------------
  394. // IndexOfSupportedKind
  395. //------------------------------------------------------------------------------
  396. // On entry, kindIndex identifies the preferred kind in kindList.
  397. // Returns in kindIndex the index into kindList of a type for which editors are
  398. // available.  If no editor is available for any kind, kindIndex is unchanged
  399. // and false is returned.
  400. ODStatic ODBoolean IndexOfSupportedKind(
  401.                         ODTypeList*            kindList,
  402.                         ODUShort*            kindIndex,
  403.                         ODEditor            editorID,
  404.                         ODNameSpaceManager*    nsm)
  405. {
  406.     Environment* ev = somGetGlobalEnvironment();
  407.  
  408.     ODUShort kindItems = kindList->Count(ev);
  409.  
  410.     if ( (*kindIndex > 1) && (*kindIndex <= kindItems) )
  411.     {
  412.          TempODType initialKind = GetTypeListItem(kindList, *kindIndex);
  413.          if ( EditorSupportsKind(nsm, editorID, initialKind) )
  414.              return kODTrue;
  415.      }
  416.  
  417.     ODBoolean result = kODFalse;
  418.     ODUShort index = 1;
  419.     ODTypeListIterator* iter = kindList->CreateTypeListIterator(ev);
  420.  
  421.     TempODType kind = kODNULL;
  422.     for (kind = iter->First(ev);
  423.          iter->IsNotComplete(ev);
  424.          kind = iter->Next(ev))
  425.     {
  426.          if ( EditorSupportsKind(nsm, editorID, kind) )
  427.         {
  428.             *kindIndex = index;
  429.             result = kODTrue;
  430.             break;
  431.         }
  432.         ODDisposePtr(kind);
  433.         kind = kODNULL;
  434.         ++index;
  435.     }
  436.     delete iter;
  437.  
  438.     return result;
  439. }    
  440.  
  441. //==============================================================================
  442. // Class TranslationDialog
  443. //==============================================================================
  444.  
  445. //------------------------------------------------------------------------------
  446. // TranslationDialog::TranslationDialog
  447. //------------------------------------------------------------------------------
  448. TranslationDialog::TranslationDialog()
  449. {
  450.     fSession = kODNULL;
  451. }
  452.  
  453. //------------------------------------------------------------------------------
  454. // TranslationDialog::~TranslationDialog
  455. //------------------------------------------------------------------------------
  456. TranslationDialog::~TranslationDialog()
  457. {
  458. }
  459.  
  460. //------------------------------------------------------------------------------
  461. // TranslationDialog::InitTranslationDialog
  462. //------------------------------------------------------------------------------
  463. void TranslationDialog::InitTranslationDialog(ODSession* session)
  464. {
  465.     fSession = session;
  466. }
  467.  
  468. //------------------------------------------------------------------------------
  469. // TranslationDialog::ShowPartTranslateDialog
  470. //------------------------------------------------------------------------------
  471. ODBoolean  TranslationDialog::ShowPartTranslateDialog(ODPartWrapper* partWrapper)
  472. {
  473.     Environment *ev = somGetGlobalEnvironment();
  474.     ODTypeList*    kindList = kODNULL;
  475.     ODTypeList*    translateToList = kODNULL;
  476.     OrderedCollection* translateFromList = kODNULL;
  477.     
  478.     ODVolatile(kindList);
  479.     ODVolatile(translateToList);
  480.     ODVolatile(translateFromList);
  481.  
  482.     ODBoolean translationSuccessful = kODFalse;
  483.  
  484.     TRY
  485.         ODBinding* binding = fSession->GetBinding(ev);
  486.         ODNameSpaceManager* nsm = fSession->GetNameSpaceManager(ev);
  487.         ODStorageUnit* storageUnit = partWrapper->GetStorageUnit(ev);
  488.         
  489.         // Create the list of kinds and translations
  490.         kindList = fSession->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  491.         
  492.         ContentValueTypes(storageUnit, kindList);
  493.  
  494.         { TempODEditor tempEditor = GetCurrentEditorForPart(partWrapper);
  495.           GetAllKindsForEditor(nsm, kindList, tempEditor);
  496.         }
  497.  
  498.         translateToList = fSession->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  499.         
  500.         translateFromList = new OrderedCollection;
  501.         
  502.         GetDestinationKindsList(kindList, translateToList, translateFromList, fSession);
  503.         
  504.         if (translateToList->Count(ev) == 0)
  505.         {
  506.             TempODName         partName    = ODGetPOName(ev, partWrapper,0);
  507.             Str255     partNameString = "\p";
  508.             GetITextPString( partName, partNameString );
  509.  
  510.             ParamText(partNameString, "\p", "\p", "\p");
  511.     
  512.             fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  513.             ShowAlert(ev, kODNoTransAlert, GetODButtonKeyFilterProc(), fSession);
  514.             fSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  515.         }
  516.         else
  517.         {
  518.             fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  519.         
  520.             ODUShort selectedKind = 0;
  521.             ODEditor editorID = kODNULL;
  522.             ODBoolean result = this->ShowTranslateDialog(translateToList, 
  523.                                                             &selectedKind, 
  524.                                                             &editorID,
  525.                                                             kODTrue,
  526.                                                             kODFalse);
  527.         
  528.             TempODEditor tempEditorID = editorID; // make sure it is deleted eventually
  529.             
  530.             fSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  531.         
  532.             if ( result )
  533.             {
  534.                 TempODType toKind = GetTypeListItem(translateToList, selectedKind);
  535.                 TempODType fromKind = GetTypeListItem(kindList, GetOrderedCollectionElement(translateFromList, selectedKind));
  536.     
  537.                 if ( fromKind && toKind )
  538.                 {
  539.                     // If fromKind does not yet exist, force part to change to that kind.
  540.                     // Otherwise, force the part to externalize any changes to its storage unit.
  541.                     if ( !storageUnit->Exists(ev, kODPropContents, fromKind, 0) )
  542.                         partWrapper->ChangeKind(ev, fromKind);
  543.                     else
  544.                         partWrapper->Externalize(ev);
  545.     
  546.                     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fromKind, 0, kODPosUndefined);
  547.                     TempODStorageUnitView fromView = storageUnit->CreateView(ev);
  548.                     
  549.                     storageUnit->Focus(ev, kODPropContents, kODPosAll, kODTypeAll, 0, kODPosUndefined);
  550.     
  551.                     storageUnit->AddValue( ev, toKind );
  552.                     TempODStorageUnitView toView = storageUnit->CreateView(ev);
  553.                     
  554.                     ODTranslation* translation = fSession->GetTranslation(ev);
  555.             
  556.                     translation->TranslateView(ev, fromView, toView);
  557.                     
  558.                     ChangeKindAndEditor(ev, partWrapper, toKind, editorID, nsm);
  559.     
  560.                     translationSuccessful = kODTrue;
  561.                 }
  562.             }
  563.         }
  564.     
  565.     CATCH_ALL
  566.         WARN("ShowPartTranslateDialog caught exception %d\n", ErrorCode());
  567.         ODDeleteObject(kindList);
  568.         ODDeleteObject(translateToList);
  569.         ODDeleteObject(translateFromList);
  570.         RERAISE;
  571.     ENDTRY
  572.  
  573.     delete kindList;
  574.     delete translateToList;
  575.     delete translateFromList;
  576.  
  577.     return translationSuccessful;
  578. }
  579.  
  580. //------------------------------------------------------------------------------
  581. // TranslationDialog::ShowTranslateDialog
  582. //------------------------------------------------------------------------------
  583. ODBoolean  TranslationDialog::ShowTranslateDialog(
  584.                 ODTypeList*    translateToList,
  585.                 ODUShort*    selectedKind,
  586.                 ODEditor*    editor,
  587.                 ODBoolean    canChangeEditor,
  588.                 ODBoolean    forPaste)
  589. {
  590.     short              itemHit = kODTransCancelBtn;
  591.     short            itemType;
  592.     Handle            itemHandle;
  593.     ControlHandle    kindPopupControlHandle;
  594.     ControlHandle    editorPopupControlHandle;
  595.     Rect            itemRect;
  596.     Rect            editorPopupRect;
  597.     ODBoolean        translationSuccessful = kODFalse;
  598.     Environment     *ev = somGetGlobalEnvironment();
  599.     ODUShort        selectedEditor = 0;
  600.     ODSLong            refSaved;
  601.     OSErr            resErr;
  602.     ODUShort        kindIndex = ( *selectedKind > 0 ? *selectedKind : 1);
  603.  
  604.     DialogPtr          dlg;                        ODVolatile(dlg);
  605.     WindowPtr        savePort;                    ODVolatile(savePort);
  606.     UserItemUPP        DrawEditorNameUPP = kODNULL;ODVolatile(DrawEditorNameUPP);
  607.     EditorSet*        editorList = kODNULL;        ODVolatile(editorList);
  608.     MenuHandle        kindMenu = kODNULL;            ODVolatile(kindMenu);
  609.     MenuHandle        editorMenu = kODNULL;        ODVolatile(editorMenu);
  610.     
  611.     {
  612.         CUsingLibraryResources r;
  613.         dlg  = ODGetNewDialog(ev, (forPaste ? kODTransDlgID : kODPartTransDlgID), fSession, kNoDefaultButton);
  614.     }
  615.  
  616.     if (dlg)
  617.     {
  618.         GetPort(&savePort);
  619.         TRY
  620.             SetPort(dlg);
  621.     
  622.             { CUsingLibraryResources r;
  623.                 SetDialogTextStyle(dlg, (forPaste ? kODTransDlgID : kODPartTransDlgID),
  624.                         smCurrentScript);
  625.             }
  626.     
  627.             // Initialize control handles
  628.             GetDialogItem(dlg, kODTransKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &itemRect);
  629.             GetDialogItem(dlg, kODTransEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &editorPopupRect);
  630.     
  631.             // Set the draw routine for the default button outline item
  632.             GetDialogItem(dlg, kODTransDefaultButtonOutline, &itemType, &itemHandle, &itemRect);
  633.             SetDialogItem(dlg, kODTransDefaultButtonOutline, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  634.     
  635.             // Set up Kind Menu
  636.             refSaved = BeginUsingLibraryResources();
  637.             kindMenu = GetMenu(kODTransKindMenu);
  638.             resErr = ResError();
  639.             EndUsingLibraryResources(refSaved);
  640.             THROW_IF_NULL(kindMenu, resErr ? resErr : resNotFound);
  641.     
  642.             if (translateToList->Count(ev) == 0 )
  643.             {
  644.                 AppendMenu(kindMenu, "\p");
  645.                 HiliteControl(kindPopupControlHandle, kControlInactive);
  646.             }
  647.             else
  648.             {
  649.                 AddTypesToMenu(translateToList, kindMenu, fSession);
  650.                 if ( !canChangeEditor )
  651.                     EnableTypesInMenu(translateToList, kindMenu, *editor, fSession->GetNameSpaceManager(ev));
  652.             }
  653.             SetControlMinimum(kindPopupControlHandle, 1);
  654.             SetControlMaximum(kindPopupControlHandle, translateToList->Count(ev));
  655.     
  656.             // Set up Editor Menu
  657.             refSaved = BeginUsingLibraryResources();
  658.             editorMenu = GetMenu(kODTransEditorMenu);
  659.             resErr = ResError();
  660.             EndUsingLibraryResources(refSaved);
  661.             THROW_IF_NULL(editorMenu, resErr ? resErr : resNotFound);
  662.     
  663.             // If an editor was specified, display that editor as static text in place
  664.             // of the popup, and disable translation kinds not supported by the editor
  665.             if ( canChangeEditor )
  666.             {
  667.                 // Pick a supported kind and create the editor list
  668.                 editorList = InitialEditorSetup(
  669.                                     translateToList,
  670.                                     &kindIndex,
  671.                                     editorMenu, 
  672.                                     editorPopupControlHandle, 
  673.                                     fSession);
  674.  
  675.                 ODBoolean anyEditor = (editorList->GetEditorCount() > 0);
  676.                 EnableOkButton(dlg, anyEditor);
  677.  
  678.                 if ( anyEditor )
  679.                 {
  680.                     if ( *editor != kODNULL )
  681.                         selectedEditor = IndexOfEditorInList(editorList, *editor);
  682.                     if ( selectedEditor == 0 )
  683.                         selectedEditor = 1;
  684.         
  685.                     SetControlValue(editorPopupControlHandle, selectedEditor);
  686.                         
  687.                     HideDialogItem(dlg, kODTransEditorLabel);
  688.                     HideDialogItem(dlg, kODTransEditorText);
  689.                     HideDialogItem(dlg, kODTransNoEditorText);
  690.                 }
  691.                 else
  692.                 {
  693.                     HideDialogItem(dlg, kODTransEditorPopup);
  694.                     HideDialogItem(dlg, kODTransEditorText);
  695.                 }
  696.             }
  697.             else
  698.             {
  699.                 // Pick a supported kind
  700.                 ODBoolean anyKindSupported = IndexOfSupportedKind(
  701.                                     translateToList, 
  702.                                     &kindIndex, 
  703.                                     *editor, 
  704.                                     fSession->GetNameSpaceManager(ev));
  705.                 
  706.                 EnableOkButton(dlg, anyKindSupported);
  707.  
  708.                 // Set text of static editor item
  709.                 DisposeGlobalODNameAndZeroPtr(&gEditorName);
  710.                 if ( GetUserEditorFromEditor(fSession->GetNameSpaceManager(ev), *editor, &gEditorName) )
  711.                 {
  712.                     GetDialogItem(dlg, kODTransEditorText, &itemType, &itemHandle, &itemRect);
  713.                     DrawEditorNameUPP = NewUserItemProc(DrawEditorName);
  714.                     SetDialogItem(dlg, kODTransEditorText, userItem+itemDisable, (Handle) DrawEditorNameUPP, &itemRect);
  715.                 }
  716.     
  717.                 HideDialogItem(dlg, kODTransEditorPopup);
  718.                 HideDialogItem(dlg, kODTransNoEditorText);
  719.             }
  720.     
  721.             SetControlValue(kindPopupControlHandle, kindIndex);
  722.  
  723.             ShowWindow(dlg);
  724.  
  725.             do {
  726.                 refSaved = BeginUsingLibraryResources();
  727.                 ModalDialog(GetODButtonKeyFilterProc(), &itemHit);
  728.                 EndUsingLibraryResources(refSaved);
  729.     
  730.                 switch (itemHit)
  731.                 {
  732.                     case kODTransKindPopup:
  733.                         ODSShort kindItem = (ODUShort) GetControlValue(kindPopupControlHandle);
  734.                         if (kindItem != kindIndex)
  735.                         {
  736.                             if ( canChangeEditor )
  737.                             {
  738.                                 TempODEditor selectedEditorID = GetThisEditorFromList(selectedEditor, editorList);
  739.  
  740.                                 editorList->RemoveAllEditors();
  741.                                 TempODType toKind = GetTypeListItem(translateToList, kindItem);
  742.                                 ODBoolean anyEditors = SetupEditorMenu(
  743.                                                             toKind,
  744.                                                             editorList, 
  745.                                                             editorMenu, 
  746.                                                             editorPopupControlHandle, 
  747.                                                             fSession);
  748.                                 EnableOkButton(dlg, anyEditors);
  749.                                 
  750.                                 ODUShort newEditor = (ODUShort) GetControlValue(editorPopupControlHandle);
  751.                                 ODSShort selectedEditor = IndexOfEditorInList(editorList, selectedEditorID);
  752.  
  753.                                 if ( (selectedEditor != 0 ) && (newEditor != selectedEditor) )
  754.                                 {
  755.                                     CUsingLibraryResources r;
  756.                                     SetControlValue(editorPopupControlHandle, selectedEditor);
  757.                                 }
  758.                                 else
  759.                                 {
  760.                                     selectedEditor = newEditor;
  761.                                     SetPort(dlg);
  762.                                     InvalRect(&editorPopupRect);    // Redraw the popup
  763.                                 }
  764.                             }
  765.                             kindIndex = kindItem;
  766.                         }
  767.                         break;
  768.     
  769.                     case kODTransEditorPopup:
  770.                         selectedEditor = (ODUShort) GetControlValue(editorPopupControlHandle);
  771.                         break;
  772.     
  773.                     default:
  774.                         break;
  775.                 }
  776.             } while ( (itemHit != kODTransOKBtn) && (itemHit != kODTransCancelBtn) );
  777.     
  778.             if ( itemHit == kODTransOKBtn ) 
  779.             {
  780.                 *selectedKind = kindIndex;
  781.                 if ( canChangeEditor )
  782.                 {
  783.                     ODEditor newEditor = GetThisEditorFromList(selectedEditor, editorList);
  784.                     if ( newEditor )
  785.                     {
  786.                         ODDisposePtr((ODPtr) *editor);
  787.                         *editor = newEditor;
  788.                     }
  789.                 }
  790.             }
  791.     
  792.         CATCH_ALL
  793.             ODDeleteObject(editorList);
  794.         
  795.             ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  796.     
  797.             refSaved = BeginUsingLibraryResources();
  798.             if ( kindMenu )
  799.             {
  800.                 DeleteMenu(kODTransKindMenu);
  801.                 ReleaseResource((Handle) kindMenu);
  802.             }
  803.             if ( editorMenu )
  804.             {
  805.                 DeleteMenu(kODTransEditorMenu);
  806.                 ReleaseResource((Handle) editorMenu);
  807.             }
  808.             DisposeDialog(dlg);
  809.             EndUsingLibraryResources(refSaved);
  810.  
  811.             DisposeGlobalODNameAndZeroPtr(&gEditorName);
  812.  
  813.             SetPort(savePort);
  814.             RERAISE;
  815.         ENDTRY
  816.  
  817.         ODDeleteObject(editorList);
  818.     
  819.         ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  820.  
  821.         refSaved = BeginUsingLibraryResources();
  822.         if ( kindMenu )
  823.         {
  824.             DeleteMenu(kODTransKindMenu);
  825.             ReleaseResource((Handle) kindMenu);
  826.         }
  827.         if ( editorMenu )
  828.         {
  829.             DeleteMenu(kODTransEditorMenu);
  830.             ReleaseResource((Handle) editorMenu);
  831.         }
  832.         DisposeDialog(dlg);
  833.         EndUsingLibraryResources(refSaved);
  834.     
  835.         DisposeGlobalODNameAndZeroPtr(&gEditorName);
  836.  
  837.         SetPort(savePort);
  838.     }
  839.  
  840.     return (itemHit == kODTransOKBtn);
  841. }
  842.